//请求根路径
rootPath="/serverlite";

//对后台数据的操作类
var Dao=function(){};

//保存或更新一条数据
Dao.saveOrUpdate=function(table,vo,func){
    $.post(rootPath+"/system/common/saveorupdate",{table:table,vo:JSON.stringify(vo)},func,"json");
};

//删除数据
Dao.del=function(table,ids,func){
    $.post(rootPath+"/system/common/delete",{table:table,ids:ids},func,"json");
};

//获取单表所有数据
Dao.all=function(table,func){
    $.post(rootPath+"/system/common/all",{table:table},func,"json");
};

//根据ID获取一条数据
Dao.get=function(table,id,func){
    $.post(rootPath+"/system/common/get",{table:table,id:id},func,"json");
};

//根据sql查询数据集
Dao.many=function(sql,func){
    $.post(rootPath+"/system/common/many",{sql:sql},func,"json");
};

//获取分页列表(单表)
Dao.list=function(table,where,sortField,sortOrder,pageSize,pageIndex,func){
    $.post(rootPath+"/system/common/list",{table:table,where:where,sortField:sortField,sortOrder:sortOrder,pageSize:pageSize,pageIndex:pageIndex},func,"json");
};

//获取分页列表(多表联合)
Dao.grid=function(sql,sortField,sortOrder,pageSize,pageIndex,func){
    $.post(rootPath+"/system/common/grid",{sql:sql,sortField:sortField,sortOrder:sortOrder,pageSize:pageSize,pageIndex:pageIndex},func,"json");
};

//更新数据的方法(基本)
Dao.update=function(){
    var arr = new Array();
    for(var i=1;i<arguments.length-1;i++){
        var arg = arguments[i];
        arr.push(arg);
    }
    $.post(rootPath+"/system/common/update",{sql:arguments[0],params:JSON.stringify(arr)},arguments[arguments.length-1],"json");
};

//查询数据的方法(基本),返回json数组
Dao.query=function(){
    var arr = new Array();
    for(var i=1;i<arguments.length-1;i++){
        var arg = arguments[i];
        arr.push(arg);
    }
    $.post(rootPath+"/system/common/query",{sql:arguments[0],params:JSON.stringify(arr)},arguments[arguments.length-1],"json");
};

//批量数据更新操作(基本)
Dao.batch=function(){
    $.post(rootPath+"/system/common/batch",{sql:arguments[0],params:JSON.stringify(arguments[1])},arguments[2],"json");
};

//调用存储过程(基本)
Dao.callProc=function(){
    var arr = new Array();
    for(var i=1;i<arguments.length-1;i++){
        var arg = arguments[i];
        arr.push(arg);
    }
    $.post(rootPath+"/system/common/callproc",{procName:arguments[0],params:JSON.stringify(arr)},arguments[arguments.length-1],"json");
};

//Session操作类
var Session=function(){};

//向Session中设置值
Session.set=function(key,vo,func){
    $.post(rootPath+"/system/common/setsession",{key:key,vo:JSON.stringify(vo)},func,"json");
};

//从Session中获取值
Session.get=function(key,func){
    $.post(rootPath+"/system/common/getsession",{key:key},func,"json");
};

//Url地址的操作类
var Url=function(){};

//获取地址栏参数
Url.getParam=function(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
};

